package com.xjy.web.controller.system;

import java.util.List;
import java.util.Arrays;

import com.xjy.system.domain.bo.BaseAuditBo;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.annotation.Log;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.enums.BusinessType;
import com.xjy.system.domain.vo.SysDepositVo;
import com.xjy.system.domain.bo.SysDepositQueryBo;
import com.xjy.system.domain.bo.SysDepositAddBo;
import com.xjy.system.domain.bo.SysDepositEditBo;
import com.xjy.system.service.ISysDepositService;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 押金基础信息Controller
 *
 * @author xjy
 * @date 2022-03-23
 */
@Api(value = "押金基础信息控制器", tags = {"押金基础信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/deposit")
public class SysDepositController extends BaseController {

	private final ISysDepositService iSysDepositService;

	/**
	 * 查询押金基础信息列表
	 */
	@ApiOperation("查询押金基础信息列表")
	@PreAuthorize("@ss.hasPermi('system:deposit:list')")
	@GetMapping("/list")
	public TableDataInfo<SysDepositVo> list(@Validated SysDepositQueryBo bo) {
		startPage();
		return iSysDepositService.queryPageList(bo);
	}

	/**
	 * 导出押金基础信息列表
	 */
	@ApiOperation("导出押金基础信息列表")
	@PreAuthorize("@ss.hasPermi('system:deposit:export')")
	@Log(title = "押金基础信息", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult<SysDepositVo> export(@Validated SysDepositQueryBo bo) {
		List<SysDepositVo> list = iSysDepositService.queryList(bo);
		ExcelUtil<SysDepositVo> util = new ExcelUtil<SysDepositVo>(SysDepositVo.class);
		return util.exportExcel(list, "押金基础信息");
	}

	/**
	 * 获取押金基础信息详细信息
	 */
	@ApiOperation("获取押金基础信息详细信息")
	@PreAuthorize("@ss.hasPermi('system:deposit:query')")
	@GetMapping("/{id}")
	public AjaxResult<SysDepositVo> getInfo(@NotNull(message = "主键不能为空")
											@PathVariable("id") Long id) {
		return AjaxResult.success(iSysDepositService.queryById(id));
	}

	/**
	 * 新增押金基础信息
	 */
	@ApiOperation("新增押金基础信息")
	@PreAuthorize("@ss.hasPermi('system:deposit:add')")
	@Log(title = "押金基础信息", businessType = BusinessType.INSERT)
	@RepeatSubmit
	@PostMapping()
	public AjaxResult<Void> add(@Validated @RequestBody SysDepositAddBo bo) {
		return toAjax(iSysDepositService.insertByAddBo(bo) ? 1 : 0);
	}

	/**
	 * 修改押金基础信息
	 */
	@ApiOperation("修改押金基础信息")
	@PreAuthorize("@ss.hasPermi('system:deposit:edit')")
	@Log(title = "押金基础信息", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping("/edit")
	public AjaxResult<Void> edit(@Validated @RequestBody SysDepositEditBo bo) {
		return toAjax(iSysDepositService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 修改押金基础信息
	 */
	@ApiOperation("修改押金基础信息")
	@PreAuthorize("@ss.hasPermi('system:deposit:edit')")
	@Log(title = "押金基础信息", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping("/audit")
	public synchronized AjaxResult<Void> audit(@Validated @RequestBody BaseAuditBo bo) {
		return toAjax(iSysDepositService.auditByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 删除押金基础信息
	 */
	@ApiOperation("删除押金基础信息")
	@PreAuthorize("@ss.hasPermi('system:deposit:remove')")
	@Log(title = "押金基础信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] ids) {
		return toAjax(iSysDepositService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
	}
}
